/**
 * Copyright (C), 2012-2018, 联奕科技有限公司
 * FileName: SmsCodeProcessor
 * Author:   石贵武
 * Date:     2018\3\12 0012 11:52
 * Description: 短信处理器
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhoudongxiu.security.core.vaildators.processor;

import com.zhoudongxiu.security.core.constants.SecurityConstants;
import com.zhoudongxiu.security.core.sms.SmsCodeSender;
import com.zhoudongxiu.security.core.vaildators.code.ValidateCode;
import com.zhoudongxiu.security.core.vaildators.processor.impl.AbstractValidateCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 〈一句话功能简述〉<br> 
 * 〈短信处理器〉
 *
 * @author 石贵武
 * @create 2018\3\12 0012
 * @since 1.0.0
 */
@Component("SmsCodeProcessor")
public class SmsCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

    @Autowired
    private SmsCodeSender smsCodeSender;
    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
        String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE;
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
        smsCodeSender.send(mobile, validateCode.getCode());
    }
}